package br.com.jk.cont.planocontas;

import br.com.jk.master.Master;
import br.com.jk.usuario.jtable.UsuarioJTableUtil;
import br.com.jk.util.Util;
import java.awt.event.KeyEvent;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author camilo
 */
public class PlanoContasJDialog extends javax.swing.JDialog {

  private static PlanoContasJDialog dialog;
  private static final long serialVersionUID = 1L;
  // Model da tabela
  PlanoContasTableModel planoTm = new PlanoContasTableModel();
  List<PlanoContas> lstForn;
//  atributos utilizados nas pesquisas externas
  private JTextField idPesquisa;
  private JTextField razaoPesquisa;
  private boolean modoConsultaExt;

  public static PlanoContasJDialog getInstance(java.awt.Frame parent, boolean modal) {
    if (dialog == null) {
      dialog = new PlanoContasJDialog(parent, modal);
    }
    return dialog;
  }

  public static PlanoContasJDialog getInstance(java.awt.Frame parent, boolean modal, JTextField id, JTextField razao) {
    if (dialog == null) {
      dialog = new PlanoContasJDialog(parent, modal, id, razao);
    }
    return dialog;
  }

  /**
   * Creates new form FornecedorJDialog
   */
  private PlanoContasJDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    criaModel();

    setLocationRelativeTo(null);
    listar();
    jlFiltro.setVisible(false);
  }

  private PlanoContasJDialog(java.awt.Frame parent, boolean modal, JTextField id, JTextField razao) {
    super(parent, modal);
    this.idPesquisa = id;
    this.razaoPesquisa = razao;
    this.modoConsultaExt = true;

    initComponents();
    criaModel();

    setLocationRelativeTo(null);
    listar();
    jlFiltro.setVisible(false);
  }

  private void criaModel() {
    jtPlano.setModel(planoTm);

    planoTm.sorter(jtPlano, planoTm);

    UsuarioJTableUtil.alteraJTable(planoTm, jtPlano, "jtPlano", Master.usuarioLogado);
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {
    java.awt.GridBagConstraints gridBagConstraints;

    JtbMaster = new javax.swing.JToolBar();
    jbNovo = new javax.swing.JButton();
    jbSalvar = new javax.swing.JButton();
    jbEditar = new javax.swing.JButton();
    jbCancelar = new javax.swing.JButton();
    jbExcluir = new javax.swing.JButton();
    jbBuscar = new javax.swing.JButton();
    jbRelatorio = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    jbRefresh = new javax.swing.JButton();
    jlFiltro = new javax.swing.JLabel();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    jbJTable = new javax.swing.JButton();
    jSplitPane1 = new javax.swing.JSplitPane();
    jScrollPane1 = new javax.swing.JScrollPane();
    jtPlano = new javax.swing.JTable();
    jpDados = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    jtfId = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jtfDescricao = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jtfNatureza = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    jtfObservacao = new javax.swing.JTextField();
    jcbTitulo = new javax.swing.JCheckBox();
    jsNivel = new javax.swing.JSpinner();
    jLabel6 = new javax.swing.JLabel();
    jftfCod = new javax.swing.JFormattedTextField();
    jftfCodPai = new javax.swing.JFormattedTextField();
    jcbContaBanco = new javax.swing.JCheckBox();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Cadastro do Plano de Contas");
    addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowClosed(java.awt.event.WindowEvent evt) {
        formWindowClosed(evt);
      }
    });

    JtbMaster.setOrientation(javax.swing.SwingConstants.VERTICAL);
    JtbMaster.setRollover(true);

    jbNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-new.png"))); // NOI18N
    jbNovo.setToolTipText("Novo Registro");
    jbNovo.setFocusable(false);
    jbNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbNovo.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbNovoMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbNovoMouseExited(evt);
      }
    });
    jbNovo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbNovoActionPerformed(evt);
      }
    });
    JtbMaster.add(jbNovo);

    jbSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-save-hd.png"))); // NOI18N
    jbSalvar.setToolTipText("Salvar Registro");
    jbSalvar.setEnabled(false);
    jbSalvar.setFocusable(false);
    jbSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbSalvar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbSalvarMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbSalvarMouseExited(evt);
      }
    });
    jbSalvar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbSalvarActionPerformed(evt);
      }
    });
    JtbMaster.add(jbSalvar);

    jbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-edit.png"))); // NOI18N
    jbEditar.setToolTipText("Alterar registro");
    jbEditar.setEnabled(false);
    jbEditar.setFocusable(false);
    jbEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbEditar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbEditarMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbEditarMouseExited(evt);
      }
    });
    jbEditar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbEditarActionPerformed(evt);
      }
    });
    JtbMaster.add(jbEditar);

    jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/dialog-cancel.png"))); // NOI18N
    jbCancelar.setToolTipText("Cancelar");
    jbCancelar.setEnabled(false);
    jbCancelar.setFocusable(false);
    jbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbCancelarMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbCancelarMouseExited(evt);
      }
    });
    jbCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbCancelarActionPerformed(evt);
      }
    });
    JtbMaster.add(jbCancelar);

    jbExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/archive-remove.png"))); // NOI18N
    jbExcluir.setMnemonic('e');
    jbExcluir.setToolTipText("Excluir");
    jbExcluir.setEnabled(false);
    jbExcluir.setFocusable(false);
    jbExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbExcluir.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbExcluirMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbExcluirMouseExited(evt);
      }
    });
    jbExcluir.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbExcluirActionPerformed(evt);
      }
    });
    JtbMaster.add(jbExcluir);

    jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/edit-find.png"))); // NOI18N
    jbBuscar.setMnemonic('b');
    jbBuscar.setToolTipText("Buscar");
    jbBuscar.setEnabled(false);
    jbBuscar.setFocusable(false);
    jbBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbBuscarMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbBuscarMouseExited(evt);
      }
    });
    jbBuscar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbBuscarActionPerformed(evt);
      }
    });
    JtbMaster.add(jbBuscar);

    jbRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/report.png"))); // NOI18N
    jbRelatorio.setToolTipText("Relatórios");
    jbRelatorio.setEnabled(false);
    jbRelatorio.setFocusable(false);
    jbRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbRelatorio.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbRelatorioMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbRelatorioMouseExited(evt);
      }
    });
    jbRelatorio.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbRelatorioActionPerformed(evt);
      }
    });
    JtbMaster.add(jbRelatorio);
    JtbMaster.add(jSeparator1);

    jbRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/view-refresh.png"))); // NOI18N
    jbRefresh.setToolTipText("Atualizar registros da lista");
    jbRefresh.setFocusable(false);
    jbRefresh.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbRefresh.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbRefresh.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbRefreshMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbRefreshMouseExited(evt);
      }
    });
    jbRefresh.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbRefreshActionPerformed(evt);
      }
    });
    JtbMaster.add(jbRefresh);

    jlFiltro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/task-attempt.png"))); // NOI18N
    JtbMaster.add(jlFiltro);
    JtbMaster.add(jSeparator2);

    jbJTable.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/view-form-table.png"))); // NOI18N
    jbJTable.setToolTipText("Grava as informações da JTable");
    jbJTable.setFocusable(false);
    jbJTable.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jbJTable.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    jbJTable.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseEntered(java.awt.event.MouseEvent evt) {
        jbJTableMouseEntered(evt);
      }
      public void mouseExited(java.awt.event.MouseEvent evt) {
        jbJTableMouseExited(evt);
      }
    });
    jbJTable.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbJTableActionPerformed(evt);
      }
    });
    JtbMaster.add(jbJTable);

    jSplitPane1.setDividerLocation(250);
    jSplitPane1.setDividerSize(10);
    jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

    /*jtPlano.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent evt){
        if (evt.getValueIsAdjusting()){
          return;
        }
        int selected = jtPlano.getSelectedRow();
        fControl.selecionado();
      }
    });

    jtPlano.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent evt){
        if (evt.getValueIsAdjusting()){
          return;
        }
        int selected = jtPlano.getSelectedColumn();
        fControl.selecionado();
      }
    });*/
    jtPlano.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jtPlano.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        jtPlanoMouseClicked(evt);
      }
    });
    jtPlano.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtPlanoKeyPressed(evt);
      }
    });
    jScrollPane1.setViewportView(jtPlano);

    jSplitPane1.setTopComponent(jScrollPane1);

    jpDados.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Dados"));
    java.awt.GridBagLayout jpDadosLayout = new java.awt.GridBagLayout();
    jpDadosLayout.columnWidths = new int[] {40, 10, 40, 10, 150, 10, 150};
    jpDados.setLayout(jpDadosLayout);

    jLabel2.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel2.setText("Id");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel2, gridBagConstraints);

    jtfId.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfId.setEnabled(false);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.gridwidth = 3;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jpDados.add(jtfId, gridBagConstraints);

    jLabel1.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel1.setText("Cod Pai");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 6;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel1, gridBagConstraints);

    jLabel3.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel3.setText("Descrição");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel3, gridBagConstraints);

    jtfDescricao.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfDescricao.setEnabled(false);
    jtfDescricao.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jtfDescricaoFocusLost(evt);
      }
    });
    jtfDescricao.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfDescricaoKeyPressed(evt);
      }
      public void keyReleased(java.awt.event.KeyEvent evt) {
        jtfDescricaoKeyReleased(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 5;
    gridBagConstraints.gridwidth = 7;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jpDados.add(jtfDescricao, gridBagConstraints);

    jLabel4.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel4.setText("Cod");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel4, gridBagConstraints);

    jLabel5.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel5.setText("Natureza");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 6;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel5, gridBagConstraints);

    jtfNatureza.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfNatureza.setEnabled(false);
    jtfNatureza.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jtfNaturezaFocusLost(evt);
      }
    });
    jtfNatureza.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfNaturezaKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 6;
    gridBagConstraints.gridy = 3;
    gridBagConstraints.ipadx = 53;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    jpDados.add(jtfNatureza, gridBagConstraints);

    jLabel7.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel7.setText("Observação");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 6;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START;
    jpDados.add(jLabel7, gridBagConstraints);

    jtfObservacao.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfObservacao.setEnabled(false);
    jtfObservacao.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jtfObservacaoFocusLost(evt);
      }
    });
    jtfObservacao.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfObservacaoKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 7;
    gridBagConstraints.gridwidth = 7;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jpDados.add(jtfObservacao, gridBagConstraints);

    jcbTitulo.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jcbTitulo.setSelected(true);
    jcbTitulo.setText("Tít.");
    jcbTitulo.setToolTipText("Marque essa opção caso o fornecedor seja Pessoa Física");
    jcbTitulo.setEnabled(false);
    jcbTitulo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jcbTituloActionPerformed(evt);
      }
    });
    jcbTitulo.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jcbTituloKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START;
    jpDados.add(jcbTitulo, gridBagConstraints);

    jsNivel.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jsNivel.setEnabled(false);
    jsNivel.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        jsNivelStateChanged(evt);
      }
    });
    jsNivel.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jsNivelKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 3;
    jpDados.add(jsNivel, gridBagConstraints);

    jLabel6.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel6.setText("Nivel");
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 2;
    jpDados.add(jLabel6, gridBagConstraints);

    try {
      jftfCod.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#.#.##.##.####")));
    } catch (java.text.ParseException ex) {
      ex.printStackTrace();
    }
    jftfCod.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    jftfCod.setEnabled(false);
    jftfCod.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jftfCod.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jftfCodFocusLost(evt);
      }
    });
    jftfCod.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jftfCodKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 4;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jpDados.add(jftfCod, gridBagConstraints);

    try {
      jftfCodPai.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("#.#.##.##.####")));
    } catch (java.text.ParseException ex) {
      ex.printStackTrace();
    }
    jftfCodPai.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    jftfCodPai.setEnabled(false);
    jftfCodPai.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jftfCodPai.addFocusListener(new java.awt.event.FocusAdapter() {
      public void focusLost(java.awt.event.FocusEvent evt) {
        jftfCodPaiFocusLost(evt);
      }
    });
    jftfCodPai.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jftfCodPaiKeyPressed(evt);
      }
    });
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 6;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    jpDados.add(jftfCodPai, gridBagConstraints);

    jcbContaBanco.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jcbContaBanco.setText("Conta Banco");
    jcbContaBanco.setEnabled(false);
    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 2;
    gridBagConstraints.gridy = 2;
    gridBagConstraints.gridheight = 2;
    jpDados.add(jcbContaBanco, gridBagConstraints);

    jSplitPane1.setRightComponent(jpDados);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(JtbMaster, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jSplitPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
      .addComponent(JtbMaster, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void jbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNovoActionPerformed
    novo();
  }//GEN-LAST:event_jbNovoActionPerformed

  private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalvarActionPerformed
    salvar();
  }//GEN-LAST:event_jbSalvarActionPerformed

  private void jbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEditarActionPerformed
    editar();
  }//GEN-LAST:event_jbEditarActionPerformed

  private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
    cancelar();
  }//GEN-LAST:event_jbCancelarActionPerformed

  private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExcluirActionPerformed
    excluir();
  }//GEN-LAST:event_jbExcluirActionPerformed

  private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscarActionPerformed
//    rn.pesquisar();
  }//GEN-LAST:event_jbBuscarActionPerformed

  private void jbRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRelatorioActionPerformed
    try {
//      Master.setJpbStatusIndeterminate(true);
//      Master.setTextJlStatus("Gerando relatório...");
      ThreadReport thReport = new ThreadReport();
      thReport.start();

    } catch (Exception e) {
      Util.msgErro(e, "Erro ao gerar o relatório");
    }
  }//GEN-LAST:event_jbRelatorioActionPerformed

  private void jbRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRefreshActionPerformed
    new PlanoContasRn().listar();
    jlFiltro.setVisible(false);
    jbBuscar.setEnabled(false);
  }//GEN-LAST:event_jbRefreshActionPerformed

  private void jtPlanoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtPlanoMouseClicked
    if (planoTm.getRowCount() > 0 && (jtfId.getText() != null && jtfDescricao != null)) {
      habilitaJb(true, false, true, false, true);
      habilitaJtf(false);
      limpar();
      selecionado();
    }
  }//GEN-LAST:event_jtPlanoMouseClicked

  private void jtfDescricaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescricaoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfObservacao.requestFocus();
    }
  }//GEN-LAST:event_jtfDescricaoKeyPressed

  private void jtfNaturezaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfNaturezaKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfDescricao.requestFocus();
    }
  }//GEN-LAST:event_jtfNaturezaKeyPressed

  private void jcbTituloKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbTituloKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jsNivel.requestFocus();
    }
  }//GEN-LAST:event_jcbTituloKeyPressed

  private void jtPlanoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtPlanoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_SPACE) {
      if (jbBuscar.isEnabled()) {
//        rn.pesquisar();
      }
    } else if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      if (modoConsultaExt) {
        selecionaRegistro();
      }
    }
  }//GEN-LAST:event_jtPlanoKeyPressed

  private void jtfDescricaoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescricaoKeyReleased
    Util.setFirstLetterUpperCase(jtfDescricao, jtfDescricao.getSelectionStart());
  }//GEN-LAST:event_jtfDescricaoKeyReleased

  private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
    dialog = null;
  }//GEN-LAST:event_formWindowClosed

  private void jbJTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbJTableActionPerformed
    getLarguraJtBanco();
  }//GEN-LAST:event_jbJTableActionPerformed

  private void jftfCodKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftfCodKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jftfCodPai.requestFocus();
    }
  }//GEN-LAST:event_jftfCodKeyPressed

  private void jftfCodFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftfCodFocusLost
    String cod = jftfCod.getText();
    cod = cod.replaceAll("\\.", "");
//    rn.getPlno().setCod(cod);;
  }//GEN-LAST:event_jftfCodFocusLost

  private void jbNovoMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbNovoMouseExited
    jbNovo.setText("");
  }//GEN-LAST:event_jbNovoMouseExited

  private void jbNovoMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbNovoMouseEntered
    jbNovo.setText("Novo");
  }//GEN-LAST:event_jbNovoMouseEntered

  private void jbSalvarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSalvarMouseEntered
    jbSalvar.setText("Salvar");
  }//GEN-LAST:event_jbSalvarMouseEntered

  private void jbEditarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbEditarMouseEntered
    jbEditar.setText("Editar");
  }//GEN-LAST:event_jbEditarMouseEntered

  private void jbCancelarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbCancelarMouseEntered
    jbCancelar.setText("Cancelar");
  }//GEN-LAST:event_jbCancelarMouseEntered

  private void jbExcluirMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbExcluirMouseEntered
    jbExcluir.setText("Excluir");
  }//GEN-LAST:event_jbExcluirMouseEntered

  private void jbBuscarMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbBuscarMouseEntered
    jbBuscar.setText("&Buscar");
  }//GEN-LAST:event_jbBuscarMouseEntered

  private void jbRelatorioMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbRelatorioMouseEntered
    jbRelatorio.setText("Relatório");
  }//GEN-LAST:event_jbRelatorioMouseEntered

  private void jbRefreshMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbRefreshMouseEntered
    jbRefresh.setText("Atualizar");
  }//GEN-LAST:event_jbRefreshMouseEntered

  private void jbJTableMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbJTableMouseEntered
    jbJTable.setText("Conf. Tabela");
  }//GEN-LAST:event_jbJTableMouseEntered

  private void jbSalvarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbSalvarMouseExited
    jbSalvar.setText("");
  }//GEN-LAST:event_jbSalvarMouseExited

  private void jbEditarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbEditarMouseExited
    jbEditar.setText("");
  }//GEN-LAST:event_jbEditarMouseExited

  private void jbCancelarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbCancelarMouseExited
    jbCancelar.setText("");
  }//GEN-LAST:event_jbCancelarMouseExited

  private void jbExcluirMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbExcluirMouseExited
    jbExcluir.setText("");
  }//GEN-LAST:event_jbExcluirMouseExited

  private void jbBuscarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbBuscarMouseExited
    jbBuscar.setText("");
  }//GEN-LAST:event_jbBuscarMouseExited

  private void jbRelatorioMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbRelatorioMouseExited
    jbRelatorio.setText("");
  }//GEN-LAST:event_jbRelatorioMouseExited

  private void jbRefreshMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbRefreshMouseExited
    jbRefresh.setText("");
  }//GEN-LAST:event_jbRefreshMouseExited

  private void jbJTableMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbJTableMouseExited
    jbJTable.setText("");
  }//GEN-LAST:event_jbJTableMouseExited

  private void jftfCodPaiFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jftfCodPaiFocusLost
    /*String cod = jftfCodPai.getText();
     cod = cod.replaceAll("\\.", "");
     rn.getPlano().setCodPai(cod);*/
  }//GEN-LAST:event_jftfCodPaiFocusLost

  private void jftfCodPaiKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftfCodPaiKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jcbTitulo.requestFocus();
    }
  }//GEN-LAST:event_jftfCodPaiKeyPressed

  private void jsNivelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jsNivelKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfNatureza.requestFocus();
    }
  }//GEN-LAST:event_jsNivelKeyPressed

  private void jtfObservacaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfObservacaoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      salvar();
    }
  }//GEN-LAST:event_jtfObservacaoKeyPressed

  private void jcbTituloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTituloActionPerformed
//    rn.getPlano().setTitulo(jcbTitulo.isSelected());
  }//GEN-LAST:event_jcbTituloActionPerformed

  private void jsNivelStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jsNivelStateChanged
//    rn.getPlano().setNivel(jsNivel.getComponentCount());
  }//GEN-LAST:event_jsNivelStateChanged

  private void jtfNaturezaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfNaturezaFocusLost
//    rn.getPlano().setNatureza(jtfNatureza.getText());
  }//GEN-LAST:event_jtfNaturezaFocusLost

  private void jtfDescricaoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfDescricaoFocusLost
//    rn.getPlano().setDescricao(jtfDescricao.getText());
  }//GEN-LAST:event_jtfDescricaoFocusLost

  private void jtfObservacaoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jtfObservacaoFocusLost
//    rn.getPlano().setObservacao(jtfObservacao.getText());
  }//GEN-LAST:event_jtfObservacaoFocusLost

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(PlanoContasJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        PlanoContasJDialog dialog = new PlanoContasJDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
        dialog.setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JToolBar JtbMaster;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JToolBar.Separator jSeparator1;
  private javax.swing.JToolBar.Separator jSeparator2;
  private javax.swing.JSplitPane jSplitPane1;
  private javax.swing.JButton jbBuscar;
  private javax.swing.JButton jbCancelar;
  private javax.swing.JButton jbEditar;
  private javax.swing.JButton jbExcluir;
  private javax.swing.JButton jbJTable;
  private javax.swing.JButton jbNovo;
  private javax.swing.JButton jbRefresh;
  private javax.swing.JButton jbRelatorio;
  private javax.swing.JButton jbSalvar;
  private javax.swing.JCheckBox jcbContaBanco;
  private javax.swing.JCheckBox jcbTitulo;
  private javax.swing.JFormattedTextField jftfCod;
  private javax.swing.JFormattedTextField jftfCodPai;
  private javax.swing.JLabel jlFiltro;
  private javax.swing.JPanel jpDados;
  private javax.swing.JSpinner jsNivel;
  private javax.swing.JTable jtPlano;
  private javax.swing.JTextField jtfDescricao;
  private javax.swing.JTextField jtfId;
  private javax.swing.JTextField jtfNatureza;
  private javax.swing.JTextField jtfObservacao;
  // End of variables declaration//GEN-END:variables

  public void novo() {
    limpar();
    habilitaJb(false, true, false, true, false);
    habilitaJtf(true);
    jftfCod.requestFocus();
  }

  private void getLarguraJtBanco() {
    UsuarioJTableUtil.setUsuarioJTable(planoTm, jtPlano, "jtPlano", Master.usuarioLogado);
  }

  public void selecionado() {
    int linha = jtPlano.getSelectedRow();//grava a linha selecionada
    int linhaSel = jtPlano.convertRowIndexToModel(linha);

    if (linhaSel >= 0) { // executa o procedimento se o JTable não estiver vazio
      int colunaSel = jtPlano.getSelectedColumn(); //grava a coluna selecionada
//      boolean pesq = rn.setEnabledPesquisa(colunaSel); // Verifica as colunas que serão habilitadas para pesquisa
      jtfId.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_ID).toString());
      jtfNatureza.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_NATUREZA).toString());
      jftfCod.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_COD).toString());
      jftfCodPai.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_COD_PAI).toString());
      jtfDescricao.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_DESCRICAO).toString());
      jcbTitulo.setSelected(Boolean.parseBoolean(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_TITULO).toString()));
      try{
      jcbContaBanco.setSelected(Boolean.parseBoolean(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_CONTABANCO).toString()));
      } catch (NullPointerException e){
        jcbContaBanco.setSelected(false);
      }
      jsNivel.getModel().setValue(Integer.parseInt(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_NIVEL).toString()));
      jtfObservacao.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_OBSERVACAO).toString());
//      rn.modoConsulta = pesq;
//      JbBuscar.setEnabled(pesq);
    }
  }

  public PlanoContas criaObjeto() {
    PlanoContas plano = new PlanoContas();
    plano.setTitulo(jcbTitulo.isSelected());
    plano.setCod(jftfCod.getText());
    plano.setCodPai(jftfCodPai.getText());
    plano.setDescricao(jtfDescricao.getText());
    plano.setObservacao(jtfObservacao.getText());
    plano.setNatureza(jtfNatureza.getText());
    plano.setNivel(Integer.parseInt(jsNivel.getModel().getValue().toString()));
    plano.setContaBanco(jcbContaBanco.isSelected());
    if (!jtfId.getText().isEmpty()) {
      plano.setId(Integer.parseInt(jtfId.getText()));
    }

    return plano;
  }

  private void salvar() {
    new PlanoContasRn().salvar(criaObjeto());
    listar();
    habilitaJb(true, false, false, false, false);
    habilitaJtf(false);
    limpar();
  }

  private void listar() {
    setJtProdutoTm(new PlanoContasRn().listar());
    limpar();
  }

  private void limpar() {
    jftfCodPai.setText(null);
    jtfDescricao.setText(null);
    jftfCod.setText(null);
    jtfObservacao.setText(null);
    jtfId.setText(null);
    jtfNatureza.setText(null);
    jcbTitulo.setSelected(false);
    jbBuscar.setEnabled(false);
    jsNivel.getModel().setValue(0);
  }

  public void setJtProdutoTm(List<PlanoContas> ct) {
    removeAllJtable();
    if (!ct.isEmpty()) {
      planoTm.adicionaLista(ct);
    }
  }

  public void setJtProdutoTm(PlanoContas ct) {
    removeAllJtable();
    if (ct != null) {
      planoTm.adiciona(ct);
    }
  }

  private void removeAllJtable() {
    while (planoTm.getRowCount() > 0) {
      planoTm.remove(0);
    }
  }

  /**
   * Determina quais os botões da barra de ferramentas ficará ativo
   *
   * @param novo
   * @param salvar
   * @param editar
   * @param cancelar
   * @param excluir
   */
  public void habilitaJb(Boolean novo, Boolean salvar, Boolean editar, Boolean cancelar,
          Boolean excluir) {
    jbNovo.setEnabled(novo);
    jbSalvar.setEnabled(salvar);
    jbEditar.setEnabled(editar);
    jbCancelar.setEnabled(cancelar);
    jbExcluir.setEnabled(excluir);
  }

  /**
   * Define se os JTextFields serão liberados para edição do usuário
   *
   * @param tf <b>True</b> - Habilitar; <b>False</b> - Desabilitar;
   */
  public void habilitaJtf(Boolean tf) {
    jftfCod.setEnabled(tf);
    jftfCodPai.setEnabled(tf);
    jtfDescricao.setEnabled(tf);
    jtfObservacao.setEnabled(tf);
    jtfNatureza.setEnabled(tf);
    jcbTitulo.setEnabled(tf);
    jsNivel.setEnabled(tf);
    jcbContaBanco.setEnabled(tf);
  }

  private void editar() {
    habilitaJb(false, true, false, true, false);
    habilitaJtf(true);
    jftfCod.requestFocus();
  }

  private void excluir() {
    new PlanoContasRn().excluir(criaObjeto());
    listar();
    limpar();
  }

  private void cancelar() {
    limpar();
    habilitaJb(true, false, false, false, false);
    habilitaJtf(false);
//    if (rn.modoConsulta) {
//      rn.modoConsulta = false;
//    } else {
    listar();
//    }
  }

  private void selecionaRegistro() {
    int linha = jtPlano.getSelectedRow();
    int linhaSel = jtPlano.convertRowIndexToModel(linha);
    idPesquisa.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_COD).toString());
    razaoPesquisa.setText(planoTm.getValueAt(linhaSel, PlanoContasTableModel.COLUNA_COD_NIVEL).toString());
    modoConsultaExt = false;
    this.dispose();
  }

  class ThreadReport extends Thread {

    @Override
    public void run() {
      try {
        new PlanoContasRn().report();
      } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
      }
    }
  }
}
